import { createRouter, createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress'   // 导入 nprogress
import 'nprogress/nprogress.css'   // 导入样式，否则看不到效果
NProgress.configure({ easing: 'ease', speed: 700, showSpinner: false })
const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/home',
            meta:{title:'首页'},
            component:()=>import('../views/Index.vue')
        },
        {
            path: '/' ,
            redirect:'/index'
        },
        {
            path: '/login',
            meta: { title: 'WR管理系统' },
            component: () => import('../views/Login.vue')
        },
        {
            path: '/index',
            meta:{title:'首页'},
            component: () => import('../views/Index.vue'),
            children: [
                {
                    path: '',
                    meta: { title: '首页' },
                    component: () => import('../views/Home.vue')
                },
                {
                    path: '/home',
                    meta: { title: '首页' },
                    component: () => import('../views/Home.vue')
                },
                {
                    path: '/device_config',
                    meta: { title: '设备配置' },
                    component: () => import('../views/device/device_config.vue')
                },
                {
                    path: '/device_control',
                    meta: { title: '设备控制' },
                    component: () => import('../views/device/device_control.vue')
                },
                {
                    path: '/permission_config',
                    meta: { title: '权限管理' },
                    component: () => import('../views/permission/permission_config.vue')
                },
                {
                    path: '/group_config',
                    meta: { title: '组管理' },
                    component: () => import('../views/permission/group_config.vue')
                },
                {
                    path: '/changepwd',
                    meta: { title: '修改密码' },
                    component: () => import('../views/user/changepwd.vue')
                },
                {
                    path: '/information',
                    meta: { title: '个人信息' },
                    component: () => import('../views/user/information.vue')
                }
            ]
        }
    ]
})
router.beforeEach((to, from, next) => {
    
    NProgress.start();  // 开始加载   
    next()  
})
router.afterEach((to,from) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    } else { 
        document.title = "WR管理系统"
    }
    NProgress.done();  // 加载完成
})
export default router